<%@ include file="/common/taglibs.jsp" %>

<head>
    <title><fmt:message key="bundleList.title"/></title>
    <meta name="menu" content="AdminMenu"/>
</head>

<div>

	
	<c:set var="delObject" scope="request"><fmt:message key="i18n.keys"/></c:set>
	<script type="text/javascript">var msgDelConfirm =
	   "<fmt:message key="delete.confirm"><fmt:param value="${delObject}"/></fmt:message>";
	</script>
	
    <h2><fmt:message key="bundleList.header"/></h2>
    <h3>
    <c:if test="${ page eq 'list' }">
		<fmt:message key="bundleList.page"/>
	</c:if>
	<c:if test="${ page eq 'empty' }">
		<fmt:message key="bundle.pageEmpty"/>
	</c:if>
	<c:if test="${ page eq 'listTextMessageTypeKeys' }">
		<fmt:message key="bundle.pageAction"/>
	</c:if>
    </h3>
    
    
    <form method="get" action="${ctx}/admin/resourcesBundles" id="searchForm" class="form-search">
    <div id="search" class="input-append">
        <input type="text" size="100" name="q" id="query" value="${param.q}"
               placeholder="<fmt:message key="search.enterTerms"/>" class="input-medium search-query"/>
        <button id="button.search" class="btn" type="submit">
            <i class="icon-search"></i>
            <fmt:message key="button.search"/>
        </button>
    </div>
    </form>
	<p>
		<c:if test="${ page eq 'list' }">
			<fmt:message key="bundleList.note"/>
		</c:if>
		<c:if test="${ page eq 'empty' }">
			<fmt:message key="bundle.emptyListNote"/>
		</c:if>
		<c:if test="${ page eq 'listTextMessageTypeKeys' }">
			<fmt:message key="bundle.actionListNote"/>
		</c:if>
	</p>
	
	<c:if test="${ page eq 'listTextMessageTypeKeys' }">
		<fmt:message key="bundle.examplesTittle"/>
	    <div class="alert alert-success fade in"><a href="#" data-dismiss="alert" class="close">&times;</a>
	    	<img class="alert-icon" src="${ ctx }/images/msg-ok.png" />
	    	<fmt:message key="bundle.exampleMessage"/>
	    </div>
	    <div class="alert alert-warning fade in" id="warningMessages"><a href="#" data-dismiss="alert" class="close">&times;</a>
	        <img class="alert-icon" src="${ ctx }/images/msg-warning.png" />
	        <fmt:message key="bundle.exampleWarningMessage"/>
	    </div>
	    <div class="alert alert-error fade in" if="errorMessages"><a href="#" data-dismiss="alert" class="close">&times;</a>
	        <img class="alert-icon" src="${ ctx }/images/msg-error.png" />
	        <fmt:message key="bundle.exampleErrorMessage"/>
	    </div>
	    <div class="alert alert-error fade in" id="exceptions"><a href="#" data-dismiss="alert" class="close">&times;</a>
	        <pre><img class="alert-icon" src="${ ctx }/images/msg-error.png" /><fmt:message key="bundle.exampleExceptionMessage"/></pre>
	    </div>
    </c:if>
	

	<s:form name="i18n" action="saveResourcesBundles" method="post" validate="false">
		<c:if test="${ page eq 'list' }">
			<div id="addRow" onclick="addRow('up')" class="btn btn-primary">
					<i class="icon-plus icon-white"></i>
	                <fmt:message key="button.addKey"/>
			</div>
			<div id="upload" onclick="window.location = 'resourcesBundlesUpload'" class="btn btn-primary">
	                <i class="icon-upload icon-white"></i>
	                <fmt:message key="button.uploadFile"/>
	        </div>
			<div id="findNew" onclick="window.location = 'resourcesBundlesEmpty'" class="btn btn-primary">
	                <i class="icon-search icon-white"></i>
	                <fmt:message key="button.findNew"/>
	        </div>
	        <div id="findAction" onclick="window.location = 'resourceBundleAction'" class="btn btn-primary">
	                <i class="icon-search icon-white"></i>
	                <fmt:message key="button.findAction"/>
	        </div>
		</c:if>
		<s:submit type="button" cssClass="btn" method="cancel" key="button.cancel" theme="simple">
                <i class="icon-remove"></i>
                <fmt:message key="button.cancel"/>
        </s:submit>
		
	    <s:submit type="button" cssClass="btn btn-primary" method="saveAll" key="button.save" theme="simple">
                <i class="icon-ok icon-white"></i>
                <fmt:message key="button.save"/>
        </s:submit>
        
		<display:table name="keys" cellspacing="0" cellpadding="0" requestURI="" 
	                   defaultsort="1" id="keys" pagesize="50"  class="table table-condensed table-striped table-hover" export="false">
	        <display:setProperty name="paging.banner.no_items_found" value="" />
	        <display:setProperty name="paging.banner.one_item_found" value="" />
	        <display:setProperty name="paging.banner.all_items_found" value="" />
	        
	        <c:if test="${ page eq 'list' }">
		        <display:column style="width: 10px" titleKey="i18n.selected">
					<input type="checkbox" name="valoresSeleccionados[${keys.id}]" />
				</display:column>
	        </c:if>
    		<display:column sortable="true" titleKey="i18n.key" style="width: 20%" >
    			<c:if test="${ page eq 'list' }">
    				${ keys.key }
    			</c:if>
    			<c:if test="${ page eq 'empty' || page eq 'listTextMessageTypeKeys' }">
	    			<small><strong>${keys.page}</strong></small><br>
					???<span style="color:red"><strong>${keys.key}</strong></span>???
					<c:if test="${ keys.exist }">
						<input type="hidden" name="valoresSeleccionados[${keys.id}]" value="${keys.key}"/>
					</c:if>
					<c:if test="${ ! keys.exist }">
						<input type="hidden" name="valoresNuevos_key['${keys.id}']" value="${keys.key}"/>
					</c:if>
    			</c:if>
    		</display:column>
			<display:column style="width: 40%" titleKey="i18n.english">
				<div class="container" style="width:95%" >
					<c:if test="${ page eq 'list' }">
							<textarea style="width:95%" cols='100' rows='1'  name="valoresCargados['${keys.id}']" >${keys.en}</textarea>
					</c:if>
					<c:if test="${ page eq 'empty' || page eq 'listTextMessageTypeKeys' }">
						<c:if test="${ keys.exist }">
							<textarea style="width:95%" cols='100' rows='1'  name="valoresCargados['${keys.id}']" >${keys.en}</textarea>
						</c:if>
						<c:if test="${ ! keys.exist }">
							<textarea style="width:95%" cols='100' rows='1'  name="valoresNuevos['${keys.id}']" >${keys.en}</textarea>
						</c:if>
					</c:if>
				</div>
			</display:column>
			<display:column style="width: 40%" titleKey="i18n.spanish">
				<div class="container" style="width:95%" >
					<c:if test="${ page eq 'list' }">
						<textarea style="width:95%" cols='100' rows='1'  name="valoresCargados_es['${keys.id}']" >${keys.es}</textarea>
					</c:if>
					<c:if test="${ page eq 'empty' || page eq 'listTextMessageTypeKeys' }">
						<c:if test="${ keys.exist }">
							<textarea style="width:95%" cols='100' rows='1'  name="valoresCargados_es['${keys.id}']" >${keys.es}</textarea>
						</c:if>
						<c:if test="${ ! keys.exist }">
							<textarea style="width:95%" cols='100' rows='1'  name="valoresNuevos_es['${keys.id}']" >${keys.es}</textarea>
						</c:if>
					</c:if>
				</div>
			</display:column>
		</display:table>	
		
		<c:if test="${ page eq 'list' }">
			<div id="addRow" onclick="addRow('down')" class="btn btn-primary">
					<i class="icon-plus icon-white"></i>
	                <fmt:message key="button.addKey"/>
			</div>
	        <s:submit type="button" cssClass="btn btn-danger" method="delete" key="button.deleteSelected"
	                    onclick="return confirmMessage(msgDelConfirm)" theme="simple">
	                    <i class="icon-trash"></i>
	                    <fmt:message key="button.deleteSelected"/>
	        </s:submit>
		</c:if>
		<s:submit type="button" cssClass="btn" method="cancel" key="button.cancel" theme="simple">
                <i class="icon-remove"></i>
                <fmt:message key="button.cancel"/>
        </s:submit>
        
		
	    <s:submit type="button" cssClass="btn btn-primary" method="saveAll" key="button.save" theme="simple">
                <i class="icon-ok icon-white"></i>
                <fmt:message key="button.save"/>
        </s:submit>
            
	</s:form>
	
</div>
<script type="text/javascript">
	var i = 1;
	
	// auto adjust the height of
	resizeTextAreas();
	
	function addRow(where) {
		var tr       = "<tr class='odd'>";
		var tdSelect = "<td style='width: 10px'></td>";
		var tdKey    = "<td style='width: 20%'>" +
        			   "<textarea style='width:95%' cols='100' rows='1' name=\"valoresNuevos_key['" + i + "']\" _vkenabled='true'></textarea>" +
        			   "</td>";
		var tdEn     = "<td style='width: 40%'>" +
					   "<div class='container' style='width:95%' >" +
		               "<textarea style='width:95%' cols='100' rows='1' name=\"valoresNuevos['" + i + "']\" _vkenabled='true'></textarea>" +
		               "</div>" +
		               "</td>";
		var tdEs     = "<td style='width: 40%'>" +
					   "<div class='container' style='width:95%' >" +
		               "<textarea style='width:95%' cols='100' rows='1' name=\"valoresNuevos_es['" + i + "']\" _vkenabled='true'></textarea>" +
		               "</div>" +
		               "</td>";            
		var endTr    = "</tr>"
		if (where == 'up') {			
			$('#keys > tbody:first').before( tr + tdSelect + tdKey + tdEn + tdEs + endTr );
		} else {
			$('#keys > tbody:last').append( tr + tdSelect + tdKey + tdEn + tdEs + endTr );
		}
		i++;
		resizeTextAreas();
		loadingoff();
	}
	
	
</script>
